package com.ITArmy.controller;

import com.ITArmy.common.ServerResponse;
import com.ITArmy.controller.base.BaseController;
import com.ITArmy.util.CheckMessage;
import com.ITArmy.util.GetUserSession;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Api(value = "消息的接口", tags = "消息的接口information")
@RequestMapping("/message")
@Controller
public class MessageController extends BaseController {
    GetUserSession getUserSession=new GetUserSession();

 /*   @RequestMapping("/getNumber")
    @ResponseBody
    @ApiOperation(value = "返回未读消息的数量，",
            httpMethod = "GET", response = ServerResponse.class)
    public ServerResponse getMessageNumber(HttpServletRequest request) {
        return ServerResponse.createBySuccess("获取成功", messageService.getUnshowMessageNumber(request));
    }
*/
    @RequestMapping("/getFocusMessage")
    @ApiOperation(value = "获取关注信息", httpMethod = "GET", response = java.lang.String.class)
    public String getFocusMessage(HttpServletRequest request,Model model) {
        model.addAttribute("focusMessage", messageService.getFocus(request));
        //将所有关注信息设为已读
        messageService.readFocus(getUserSession.getUser(request).getuId());
        return "informationQuestion";
    }

    @RequestMapping("/deleteFocusMessage")
    @ResponseBody
    @ApiOperation(value = "删除关注信息，",
            httpMethod = "DELETE", response = ServerResponse.class)
    public ServerResponse deleteFocusMessage(long fid) {
        int resultCount = messageService.deleteFocusMessage(fid);
        CheckMessage check = new CheckMessage();
        return check.getMessage(resultCount, "删除成功", "删除失败");
    }

    @RequestMapping("/getPraiseMessage")
    @ApiOperation(value = "获取点赞的信息", httpMethod = "GET", response = java.lang.String.class)
    public String getPraiseMessage(HttpServletRequest request,Model model) {
        model.addAttribute("praiseMessage", messageService.getPrise(request));
        //将所有关注信息设为已读
        messageService.readPraise(getUserSession.getUser(request).getuId());
        return "informationAgree";
    }

    @RequestMapping("/deletePraiseMessage")
    @ResponseBody
    @ApiOperation(value = "删除点赞信息，",
            httpMethod = "DELETE", response = ServerResponse.class)
    public ServerResponse deletePraiseMessage(long pid) {
        int resultCount = messageService.deletePraiseMessage(pid);
        CheckMessage check = new CheckMessage();
        return check.getMessage(resultCount, "删除成功", "删除失败");
    }

    @RequestMapping("/getCommentMessage")
    @ApiOperation(value = "获取评论的信息", httpMethod = "GET", response = java.lang.String.class)
    public String getCommentMessage(HttpServletRequest request,Model model) {
        model.addAttribute("comment", messageService.getComment(request));
        //将所有评论信息设为已读
        messageService.readComment(getUserSession.getUser(request).getuId());

        return "imformationComment";
    }

    @RequestMapping("/deleteCommentMessage")
    @ResponseBody
    @ApiOperation(value = "删除评论信息，",
            httpMethod = "DELETE", response = ServerResponse.class)
    public ServerResponse deleteCommentMessage(long cid) {
        int resultCount = messageService.deleteCommentMessage(cid);
        CheckMessage check = new CheckMessage();
        return check.getMessage(resultCount, "删除成功", "删除失败");
    }

    @RequestMapping("/getOrderMessage")
    @ApiOperation(value = "获取系统的信息", httpMethod = "GET", response = java.lang.String.class)
    public String getOrderMessage(HttpServletRequest request,Model model) {
        model.addAttribute("OrderMessage",messageService.getSystem(request));
        //将所有订单信息设为已读
        messageService.readSystem(getUserSession.getUser(request).getuId());
        return "informationFollow";
    }

    @RequestMapping("/deleteOrderMessage")
    @ResponseBody
    @ApiOperation(value = "删除订单信息，",
            httpMethod = "DELETE", response = ServerResponse.class)
    public ServerResponse deleteOrderMessage(long oid) {
        int resultCount = messageService.deleteOrderMessage(oid);
        CheckMessage check = new CheckMessage();
        return check.getMessage(resultCount, "删除成功", "删除失败");
    }

}
